import { createRouter, createWebHistory, createWebHashHistory } from 'vue-router'


import login from '@/views/Login/login.vue'



const defaultTitle = '渠道管理'


export const routes = [
  {
    path: '/',
    name: '/',
    component: login,
    meta: {
      title: '渠道管理',
      index: 0
    }
  },
  {
    path: '/home',
    name: 'home',
    // component: () => home,
    component: () => import('@/views/Home/home.vue'),
    meta: {
      title: '首页',
      index: 0
    }
  },
  {
    path: '/login',
    name: 'login',
    component: () => import('@/views/Login/login.vue'),
    meta: {
      title: '登录',
      index: 0
    }
  },

  {
    path: '/forget',
    name: 'forget',
    component: () => import('@/views/Login/forget.vue'),
    meta: {
      title: '忘记密码',
      index: 1
    }
  },

  // {
  //   path: '/changepwd',
  //   name: 'changepwd',
  //   component: () => import('@/views/Login/changepwd.vue'),
  //   meta: {
  //     title: '修改密码',
  //     index: 1
  //   }
  // },

  {
    path: '/main',
    name: 'main',
    component: () => import('@/views/Main/main.vue'),
    meta: {
      title: '功能',
      index: 1,
      keepAlive: true
    }
  },

  {
    path: '/my',
    name: 'my',
    component: () => import('@/views/My/my.vue'),
    meta: {
      title: '我的',
      index: 1,
      keepAlive: true
    }
  },

  {
    path: '/changePwd',
    name: 'changePwd',
    component: () => import('@/views/My/changePwd.vue'),
    meta: {
      title: '修改密码',
      index: 1,
    }
  },

  {
    path: '/changeInfo',
    name: 'changeInfo',
    component: () => import('@/views/My/changeInfo.vue'),
    meta: {
      title: '修改信息',
      index: 1,
    }
  },

  {
    path: '/default',
    name: 'default',
    component: () => import('@/views/Modules/default/default.vue'),
    meta: {
      // title: defaultTitle,
      index: 2,
    }
  },
  {
    path: '/defaultCard',
    name: 'defaultCard',
    component: () => import('@/views/Modules/default/defaultCard.vue'),
    meta: {
      // title: defaultTitle,
      index: 2,
      // keepAlive: true
    }
  },

  {
    path: '/defaultForm',
    name: 'defaultForm',
    component: () => import('@/views/Modules/default/defaultForm.vue'),
    meta: {
      // title: defaultTitle,
      index: 2
    }
  },



  {
    path: '/contact',
    name: 'contact',
    // component: contact,
    component: () => import('@/views/Modules/contact/contact.vue'),
    meta: {
      title: '联系人',
      index: 2,
      keepAlive: true
    }
  },
  {
    path: '/contactForm',
    name: 'contactForm',
    component: () => import('@/views/Modules/contact/contactForm.vue'),
    meta: {
      title: '联系人',
      index: 2,
      // keepAlive: false
    }
  },
  {
    path: '/contactCard',
    name: 'contactCard',
    component: () => import('@/views/Modules/contact/contactCard.vue'),
    meta: {
      title: '联系人',
      index: 2,
      // keepAlive: true
    }
  },



  {
    path: '/account',
    name: 'account',
    component: () => import('@/views/Modules/account/account.vue'),
    meta: {
      title: '医院客户',
      index: 2,
      // keepAlive: true
    }
  },
  {
    path: '/account2',
    name: 'account2',
    component: () => import('@/views/Modules/accout2/account2.vue'),
    meta: {
      title: 'OTC客户',
      index: 2,
      // keepAlive: true
    }
  },
  {
    path: '/account1',
    name: 'account1',
    component: () => import('@/views/Modules/accout1/account1.vue'),
    meta: {
      title: '商业客户',
      index: 2,
      // keepAlive: true
    }
  },


  {
    path: '/bizcalendar',
    name: 'bizcalendar',
    component: () => import('@/views/Modules/bizcalendar/bizcalendar.vue'),
    meta: {
      title: '日程安排',
      index: 2,
      keepAlive: true
    }
  },


  {
    path: '/bizcalendarAction',
    name: 'bizcalendarAction',
    component: () => import('@/views/Modules/bizcalendar/bizcalendarAction.vue'),
    meta: {
      title: '日程安排',
      index: 2,
      // keepAlive: true
    }
  },

  {
    path: '/jhgl',
    name: 'jhgl',
    // component: contact,
    component: () => import('@/views/Modules/jhgl/jhgl.vue'),
    meta: {
      title: '计划管理',
      index: 2,
      keepAlive: true
    }
  },

  {
    path: '/jhglForm',
    name: 'jhglForm',
    component: () => import('@/views/Modules/jhgl/jhglForm.vue'),
    meta: {
      title: '添加计划',
      index: 2,
    }
  },

  {
    path: '/jhglCard',
    name: 'jhglCard',
    component: () => import('@/views/Modules/jhgl/jhglCard.vue'),
    meta: {
      title: '计划管理',
      index: 2,
    }
  },

  {
    path: '/bflx',
    name: 'bflx',
    // component: contact,
    component: () => import('@/views/Modules/bflx/bflx.vue'),
    meta: {
      title: '拜访路线',
      index: 2,
      keepAlive: true
    }
  },

  {
    path: '/bflxForm',
    name: 'bflxForm',
    component: () => import('@/views/Modules/bflx/bflxForm.vue'),
    meta: {
      title: '添加路线',
      index: 2,
    }
  },

  {
    path: '/bflxCard',
    name: 'bflxCard',
    component: () => import('@/views/Modules/bflx/bflxCard.vue'),
    meta: {
      title: '拜访路线',
      index: 2,
    }
  },
  {
    path: '/sd',
    name: 'sd',
    component: () => import('@/views/Modules/sd/sd.vue'),
    meta: {
      title: '参照生单',
      index: 2,
    }
  },
  {
    path: '/sdsub',
    name: 'sdsub',
    component: () => import('@/views/Modules/sd/sdsub.vue'),
    meta: {
      title: '参照生单',
      index: 2,
    }
  },
  {
    path: '/sdnew',
    name: 'sdnew',
    component: () => import('@/views/Modules/sd/sdnew.vue'),
    meta: {
      title: '参照生单',
      index: 2,
    }
  },

  {
    path: '/flow',
    name: 'flow',
    component: () => import('@/views/Modules/flow/flow.vue'),
    meta: {
      title: '审批',
      index: 0,
    },
  },

  {
    path: '/flowCard',
    name: 'flowCard',
    component: () => import('@/views/Modules/flow/flowCard.vue'),
    meta: {
      title: '审批',
      index: 1,
    },
  },

  {
    path: '/report',
    name: 'report',
    component: () => import('@/views/Modules/report/report.vue'),
    meta: {
      title: '分析',
      index: 0,
    },
  },

  {
    path: '/reportTable',
    name: 'reportTable',
    component: () => import('@/views/Modules/report/reportTable.vue'),
    meta: {
      title: '分析',
      index: 1,
    },
  },


  {
    path: '/weekreports',
    name: 'weekreports',
    component: () => import('@/views/Modules/weekreports/weekreports.vue'),
    meta: {
      title: '工作周报',
      index: 0,
    },
  },

   {
    path: '/bfzjh',
    name: 'bfzjh',
    component: () => import('@/views/Modules/bfzjh/bfzjh.vue'),
    meta: {
      title: '周计划',
      index: 0,
    },
  },








]

const router = createRouter({
  history: createWebHashHistory(import.meta.env.BASE_URL),
  routes
})

router.beforeEach((to, from, next) => {
  if (to.meta && to.meta.title) {
    sessionStorage.setItem("stitle", to.meta.title as string)

    document.title = to.meta.title as string;
  }


  if (to.fullPath === "/login") {
    next();
    return
  }

  const isLogin = sessionStorage.getItem('isLogin')
  if (isLogin === '0') {
    next('/login')
    return
  }


  if (!to.meta.keepAlive) {
    // window.scrollTo(0, 0);
  }
  next();
  return
});

export default router
